//
//  XJCmtChargeBottomView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/7/17.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  提交按钮 +  缴费协议

#import "XJCmtChargeBottomView.h"

#import "NSAttributedString+YYText.h"
#import "YYLabel.h"
@interface XJCmtChargeBottomView()
//@property (nonatomic, strong)
@property (nonatomic, strong) YYLabel *chargeProtocolLb; //充值协议lb
@property (nonatomic, strong) UIButton *surePayButton;//确认支付btn


@end

@implementation XJCmtChargeBottomView
#pragma mark - 一 lazy
- (YYLabel *)chargeProtocolLb {
    if (!_chargeProtocolLb) {
        _chargeProtocolLb = [[YYLabel alloc] init];
        _chargeProtocolLb.userInteractionEnabled = YES;
//        _chargeProtocolLb.textAlignment = NSTextAlignmentCenter; //没用
        
        NSString *str1 = @"点击确认支付代表您已同意";
        NSString *str2 = @"《缴费协议》";
        NSString *protocalStr = [NSString stringWithFormat:@"%@%@",str1,str2];
        NSRange range2 = [protocalStr rangeOfString:str2];
        
        UIColor *blueColor = [UIColor blueColor];
        UIColor *blackColor = [UIColor blackColor];
        UIColor *clearColor = [UIColor clearColor];
        
        NSMutableAttributedString *attStrM = [[NSMutableAttributedString alloc] initWithString:protocalStr attributes:@{NSForegroundColorAttributeName:blackColor,NSFontAttributeName:XJFONTSET_R(15.0)}];
        attStrM.yy_alignment = NSTextAlignmentCenter; // ✅
        [attStrM yy_setTextHighlightRange:range2 color:blueColor backgroundColor:clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            
            if (self.xjcmtChargeBottomViewClickChargeProtocolBlock) {
                self.xjcmtChargeBottomViewClickChargeProtocolBlock();
            }
        }];
        
        _chargeProtocolLb.attributedText = attStrM;
    }
    return _chargeProtocolLb;
}

- (UIButton *)surePayButton {
    if (!_surePayButton) {
        _surePayButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_surePayButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_surePayButton setTitle:@"确认支付" forState:(UIControlStateNormal)];
        _surePayButton.layer.masksToBounds = YES;
        _surePayButton.layer.cornerRadius =  10;
        _surePayButton.backgroundColor = XJCOLOR_RGB(255, 218, 67);
        [_surePayButton addTarget:self action:@selector(surePayButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _surePayButton;
}


#pragma mark - 二 init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView {
    [self addSubview:self.chargeProtocolLb];
    
    [self addSubview:self.surePayButton];
}

#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat k30 = 30.0;
    [self.chargeProtocolLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(k30);
        make.right.equalTo(self.mas_right).offset(-k30);
        make.top.equalTo(self.mas_top).offset(10);
        make.height.mas_equalTo(22);
    }];
    
    [self.surePayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(k30);
        make.right.equalTo(self.mas_right).offset(-k30);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
        make.height.equalTo(@40);
    }];
}

#pragma mark - 四 回调事件
- (void)surePayButtonAction:(UIButton *)button {
    
    if (self.xjcmtChargeBottomViewClickSurePayBtnBlock) {
        self.xjcmtChargeBottomViewClickSurePayBtnBlock();
    }
}


@end
